package cn.edu.tju.cas.entity;

import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Set;

/**
 * Created by catold on 16/3/12.
 */
@Entity
@Table(name = "USER", schema = "dev_cas", catalog = "")
public class UserEntity implements Serializable {
    private int userId;
    private String username;
    private String password;
    private String idCard;
    private Integer status;
    private Timestamp lastVisitTime;
    private Integer isAdmin;
    private Timestamp createtime;
    private Timestamp updatetime;
    private String credit;
    private String email;
    private String appPassword;

    // user —— apply 双向映射，方便查询
//    private Set<UserGroupApplyEntity> userGroupApplyEntities;
//
//    public Set<UserGroupApplyEntity> getUserGroupApplyEntities() {
//        return userGroupApplyEntities;
//    }
//
//    public void setUserGroupApplyEntities(Set<UserGroupApplyEntity> userGroupApplyEntities) {
//        this.userGroupApplyEntities = userGroupApplyEntities;
//    }

    // 定义groupEntities 只是为了查询的时候，凑成一个json result，方便前端处理展示，insert update 的时候不用
    private Set<GroupEntity> groupEntities;

    public Set<GroupEntity> getGroupEntities() {
        return groupEntities;
    }

    public void setGroupEntities(Set<GroupEntity> groupEntities) {
        this.groupEntities = groupEntities;
    }

    @Id
    @GeneratedValue
    @Column(name = "USER_ID", nullable = false)
    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    @Basic
    @Column(name = "USERNAME", nullable = true, length = 255)
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @Basic
    @Column(name = "CREDIT", nullable = true, length = 255)
    public String getIdCard() {
        return idCard;
    }

    public void setIdCard(String idCard) {
        this.idCard = idCard;
    }

    @Basic
    @Column(name = "PASSWORD", nullable = true, length = 255)
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Basic
    @Column(name = "STATUS", nullable = true)
    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    @Basic
    @Column(name = "LAST_VISIT_TIME", nullable = true)
    public Timestamp getLastVisitTime() {
        return lastVisitTime;
    }

    public void setLastVisitTime(Timestamp lastVisitTime) {
        this.lastVisitTime = lastVisitTime;
    }

    @Basic
    @Column(name = "IS_ADMIN", nullable = true)
    public Integer getIsAdmin() {
        return isAdmin;
    }

    public void setIsAdmin(Integer isAdmin) {
        this.isAdmin = isAdmin;
    }

    @Basic
    @Column(name = "CREATETIME", nullable = true)
    public Timestamp getCreatetime() {
        return createtime;
    }

    public void setCreatetime(Timestamp createtime) {
        this.createtime = createtime;
    }

    @Basic
    @Column(name = "UPDATETIME", nullable = true)
    public Timestamp getUpdatetime() {
        return updatetime;
    }

    public void setUpdatetime(Timestamp updatetime) {
        this.updatetime = updatetime;
    }

    @Basic
    @Column(name = "CREDIT", nullable = true)
    public String getCredit() {
        return credit;
    }

    public void setCredit(String credit) {
        this.credit = credit;
    }

    @Basic
    @Column(name = "EMAIL", nullable = true)
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Basic
    @Column(name = "APP_PASSWORD", nullable = true)
    public String getAppPassword() {
        return appPassword;
    }

    public void setAppPassword(String appPassword) {
        this.appPassword = appPassword;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        UserEntity that = (UserEntity) o;

        if (userId != that.userId) return false;
        if (username != null ? !username.equals(that.username) : that.username != null) return false;
        if (password != null ? !password.equals(that.password) : that.password != null) return false;
        if (status != null ? !status.equals(that.status) : that.status != null) return false;
        if (lastVisitTime != null ? !lastVisitTime.equals(that.lastVisitTime) : that.lastVisitTime != null)
            return false;
        if (isAdmin != null ? !isAdmin.equals(that.isAdmin) : that.isAdmin != null) return false;
        if (createtime != null ? !createtime.equals(that.createtime) : that.createtime != null) return false;
        if (updatetime != null ? !updatetime.equals(that.updatetime) : that.updatetime != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = userId;
        result = 31 * result + (username != null ? username.hashCode() : 0);
        result = 31 * result + (password != null ? password.hashCode() : 0);
        result = 31 * result + (status != null ? status.hashCode() : 0);
        result = 31 * result + (lastVisitTime != null ? lastVisitTime.hashCode() : 0);
        result = 31 * result + (isAdmin != null ? isAdmin.hashCode() : 0);
        result = 31 * result + (createtime != null ? createtime.hashCode() : 0);
        result = 31 * result + (updatetime != null ? updatetime.hashCode() : 0);
        return result;
    }
}
